/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ca.trader.user;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.PrePersist;
import javax.persistence.PreUpdate;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.xml.bind.annotation.XmlRootElement;

/**
 * An entity for representing a user login record
 * @author Ahsan
 */
@Entity
@XmlRootElement
public class UserLoginHistoryRecord implements Serializable
{
	 /**
	  * This UUID of the login time
	  */
	 @Id
	 private String UUID;
	 

	 /**
	  * The login time
	  */
	 @Column(nullable = false)
	 @Temporal(TemporalType.TIMESTAMP)
	 private Date loginTime;
	 
	 /**
	  * The user for whom this record is for
	  */
	 @ManyToOne
	 @JoinColumn(nullable = false)
	 private User user;
	 

	 /**
	  * Gets the uuid
	  * @return the uuid
	  */
	 public String getUUID()
	 {
		  return UUID;
	 }

	 /**
	  * sets the UUID
	  * @param UUID the uuid
	  */
	 public void setUUID(String UUID)
	 {
		  this.UUID = UUID;
	 }

	 /**
	  * Gets the login time
	  * @return the login time
	  */
	 public Date getLastLoginTime()
	 {
		  return loginTime;
	 }

	 /**
	  * Sets the login time
	  * @param loginTime the login time
	  */
	 public void setLoginTime(Date loginTime)
	 {
		  this.loginTime = loginTime;
	 }

	 /**
	  * Gets the user
	  * @return the user
	  */
	 public User getUser()
	 {
		  return user;
	 }

	 /**
	  * Sets the user
	  * @param user the user
	  */
	 public void setUser(User user)
	 {
		  this.user = user;
	 }
	 
	 /**
	  * Sets the login time automatically before persisting or updating the record.
	  */
	 @PrePersist
	 @PreUpdate
	 private void setLoginTime()
	 {
		  setLoginTime (new Date ());
	 }
}
